import clr, sys

clr.AddReferenceByPartialName("Microsoft.Office.Interop.Outlook")

from Microsoft.Office.Interop import Outlook
from System.Reflection import *

typemap = {str: Outlook.OlUserPropertyType.olText, bool: Outlook.OlUserPropertyType.olYesNo}

class GtdProperties(object):
    def __init__(self, userProperties):
        self.properties = userProperties
        
    def __call__(self, member, *args):
        if len(member) > 3:
            modifier = member[0:3]
        if modifier == 'get':
            name = member[3:]
            if self.properties.Find(name, Missing.Value) != None:
                return self.properties.Item(name).Value
            else:
                return None
        elif modifier == 'set':
            name = member[3:]
            value = args[0]
            if self.properties.Find(name, Missing.Value) == None:
                self.properties.Add(name, typemap[type(value)], False, Missing.Value)
            self.properties.Item(name).Value = value
        else:
            return None

    def __getattribute__(self, name):
        try:
            return super(GtdProperties, self).__getattribute__(name)
        except AttributeError:
            return lambda *args: self(name, *args)
